package com.block.product.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.block.common.constant.AppRspCodeConstant;
import com.block.common.constant.RedisKeyConstant;
import com.block.common.enums.ChargeTypeEnum;
import com.block.common.model.dto.CountInfoDTO;
import com.block.common.model.dto.MemberBaseInfoDTO;
import com.block.common.service.IChannelCommonService;
import com.block.common.service.IMemberCommonService;
import com.block.common.service.LogFactory;
import com.block.common.util.LocalDateUtil;
import com.block.common.vo.ResponseVo;
import com.block.db.entity.*;
import com.block.db.mapper.MemberBaseInfoMapper;
import com.block.db.mapper.MemberSourceInfoMapper;
import com.block.db.mapper.ProductOnlieInfoMapper;
import com.block.product.model.result.UnionLoginResult;
import com.block.product.model.vo.ProductInfoVO;
import com.block.product.service.IProductBaseInfoService;
import com.block.product.service.IProductOnlieInfoService;
import com.block.product.service.IProductUnionLoginService;
import io.micrometer.core.instrument.binder.system.UptimeMetrics;
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * <p>
 * 产品上线信息 服务实现类
 * </p>
 *
 * @author
 * @since 2023-09-02
 */
@Service
public class ProductOnlieInfoServiceImpl extends ServiceImpl<ProductOnlieInfoMapper, ProductOnlieInfo> implements IProductOnlieInfoService {

    private static final Logger log = LogFactory.getProductLog();

    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    IProductBaseInfoService productBaseInfoService;
    @Autowired
    IChannelCommonService channelCommonService;
    @Autowired
    IProductUnionLoginService productUnionLoginService;
    @Autowired
    IMemberCommonService memberCommonService;
    @Autowired
    MemberSourceInfoMapper memberSourceInfoMapper;


    @Override
    public ResponseVo prodInfoList(ChannelBaseInfo channelBaseInfo, String sceneId, Long uid, String reqIp) {

        String nowDate = LocalDate.now().toString();
        String nowTime = LocalDateUtil.getNowDateStr(LocalDateUtil.SIMPLE_TIME);

        //
        MemberBaseInfoDTO memberBaseInfoDTO = memberCommonService.getMemberBaseInfo(uid);
        if (ObjectUtil.isNotEmpty(memberBaseInfoDTO) &&
                ObjectUtil.isNotEmpty(memberBaseInfoDTO.getShowProdTime())) {
//                LocalDateTime.now().isBefore(memberBaseInfoDTO.getShowProdTime())
            // 用户信息不为空，且产品展示时间不为空，且当前时间在产品展示时间之前（不展示用户产品）
            // 直接返回成功
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("dataList", new ArrayList<>());
            return new ResponseVo(AppRspCodeConstant.SUCCESS, jsonObject);
        }


        if (!ObjectUtil.equals(Integer.valueOf(1), channelBaseInfo.getShowProductFlag())) {
            // 不展示产品列表的时候，返回空几个
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("dataList", new ArrayList<>());
            return new ResponseVo(AppRspCodeConstant.SUCCESS, jsonObject);
        }

        String channelCode = channelBaseInfo.getChannelCode();


        // 查询已经上线的产品
        List<ProductOnlieInfo> onlieInfoList = this.baseMapper.getOnlineProductInfoList(sceneId, channelBaseInfo.getChannelType(), nowDate, nowTime);

        List<ProductInfoVO> dataList = new ArrayList<>();
        for (ProductOnlieInfo productOnlieInfo : onlieInfoList) {

            String outChannelArray = productOnlieInfo.getOutChannelArray();
            String inChannelArray = productOnlieInfo.getInChannelArray();

            // 检查不允许推送的渠道（outChannelArray）
            List<String> outChannelList = JSON.parseArray(outChannelArray, String.class);
            if (CollUtil.isNotEmpty(outChannelList) && outChannelList.contains(channelCode)) {
                continue;
            }

            // 检查允许推送的渠道（inChannelArray）
            List<String> inChannelList = JSON.parseArray(inChannelArray, String.class);
            if (CollUtil.isNotEmpty(inChannelList) && !inChannelList.contains(channelCode)) {
                continue;
            }

            // 2023/9/2 uv 控量 ，查询是否展示
            String redisKey = StrUtil.format(RedisKeyConstant.PRODUCT_UV_REMAIN_COUNT_KEY, nowDate, productOnlieInfo.getProductId());
            String remainNumber = stringRedisTemplate.opsForValue().get(redisKey);
            if (ObjectUtil.isNotEmpty(remainNumber) && Integer.valueOf(remainNumber) <= 0) {
                continue;
            }

            // 查询产品基本信息
            ProductBaseInfo productInfo = productBaseInfoService.getProductInfoById(productOnlieInfo.getProductId());

            ProductInfoVO productInfoVO = new ProductInfoVO();
            productInfoVO.setProductId(String.valueOf(productInfo.getId()));
            productInfoVO.setProductName(productInfo.getProductName());
            productInfoVO.setProductLogo(productInfo.getLogoUrl());
            productInfoVO.setProductTitle(productInfo.getTitleInfo());
            productInfoVO.setProductLabel(productInfo.getLabelInfo());
            productInfoVO.setShowFlag(productInfo.getShowFlag());
            productInfoVO.setDownloadFlag(productInfo.getDownloadFlag());
            productInfoVO.setMaxAmount(productInfo.getMaxAmount());
            productInfoVO.setJumpStatus(productOnlieInfo.getJumpStatus());
            productInfoVO.setRateAmountInfo(StrUtil.format("{}~{}%", productInfo.getMinRate(), productInfo.getMaxRate()));

            boolean unionFlag = ObjectUtil.equals(productInfo.getChargeType(), ChargeTypeEnum.UNION.getValue());
            productInfoVO.setUnionFlag(unionFlag);
            if (unionFlag) {
                // 2023/9/2 联登获取 产品信息
                //  用户进行撞库，确认是否显示。或者直接获取到缓存的产品信息（产品登陆信息）
                UnionLoginResult loginResult = productUnionLoginService.getUnionProductShowInfo(productInfo, uid,channelBaseInfo);
                log.info("【产品列表】产品联登【productId】{}【uid】{}【result】{}", productInfo.getId(), uid, JSON.toJSONString(loginResult));
                if (loginResult.isSuccess()) {

                    String loginUrl = loginResult.getLoginUrl();
                    if (StrUtil.isNotEmpty(loginUrl)) {
                        productInfoVO.setDetailUrl(loginResult.getLoginUrl());
                    } else {
                        productInfoVO.setDetailUrl("");
                    }
                    dataList.add(productInfoVO);
                }
            } else {
                productInfoVO.setDetailUrl(productInfo.getDetailUrl());
                // 非联登产品，直接添加显示
                dataList.add(productInfoVO);
            }
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("dataList", dataList);

        // 消息通知
        if (StrUtil.equals(sceneId, "1")) {
            countProdListUv(channelBaseInfo.getChannelCode(), reqIp);
        }

        return new ResponseVo(AppRspCodeConstant.SUCCESS, jsonObject);
    }

    /**
     * 基于渠道统计，每个产品列表的uv
     *
     * @param channelCode
     * @param reqIp
     */
    public void countProdListUv(String channelCode, String reqIp) {

        Long remainSecond = LocalDateUtil.getRemainSecondNumber();
        String redisKey = StrUtil.format(RedisKeyConstant.PROD_LIST_UV_KEY, channelCode, reqIp);
        boolean result = stringRedisTemplate.opsForValue()
                .setIfAbsent(redisKey, System.currentTimeMillis() + "", remainSecond, TimeUnit.SECONDS);

        if (result) {
            CountInfoDTO countInfoDTO = new CountInfoDTO(channelCode);
            countInfoDTO.setUvProdList(1);

            channelCommonService.updateChannelCount(countInfoDTO);
        }
    }

    /**
     * 用户匹配失败 返回价格最高的产品 依次递减
     */
    @Override
    public ResponseVo getOptimalProduct(ChannelBaseInfo channelBaseInfo, String sceneId, Long uid, String reqIp) {
        String nowDate = LocalDate.now().toString();
        String nowTime = LocalDateUtil.getNowDateStr(LocalDateUtil.SIMPLE_TIME);
        JSONObject jsonObject = new JSONObject();
        String channelCode = channelBaseInfo.getChannelCode();
        if (!ObjectUtil.equals(Integer.valueOf(1), channelBaseInfo.getShowProductFlag())) {
            // 不展示产品列表的时候，返回空几个
            jsonObject.put("dataList", new ArrayList<>());
            return new ResponseVo(AppRspCodeConstant.SUCCESS, jsonObject);
        }
        // 查询已经上线的产品
        List<ProductOnlieInfo> onlieInfoList = this.baseMapper.getOnlineProductInfoList(sceneId, channelBaseInfo.getChannelType(), nowDate, nowTime);
        MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if(memberSourceInfo == null){
            jsonObject.put("dataList", new ArrayList<>());
            return new ResponseVo(AppRspCodeConstant.SUCCESS, jsonObject);
        }
        onlieInfoList.sort((p1, p2) -> p2.getPriceAmount().compareTo(p1.getPriceAmount()));
        //获取用户的访问历史
        String redisIdKey = RedisKeyConstant.PRODUCT_OVER_ID + uid;
        Set<String> matchedProductIds = stringRedisTemplate.opsForSet().members(redisIdKey);

        onlieInfoList = filterProductInfoByZhimaFilter(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByYuQi(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByloanAmount(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByXueLi(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByJob(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByShouRu(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByHouse(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByCar(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByGjj(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByShebao(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByBaoxian(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByHubei(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByBaitiao(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByYongtu(onlieInfoList, uid);

        onlieInfoList = filterProductInfoByAge(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByCtiy(onlieInfoList, uid);

        onlieInfoList = filterProductInfoByOutCtiy(onlieInfoList, uid);


        List<ProductInfoVO> dataList = new ArrayList<>();
        for (ProductOnlieInfo productOnlieInfo : onlieInfoList) {
            String productId = String.valueOf(productOnlieInfo.getProductId());

            //跳过以匹配过的产品
            if (CollUtil.isNotEmpty(matchedProductIds) && matchedProductIds.contains(productId)) {
                continue;
            }

            String outChannelArray = productOnlieInfo.getOutChannelArray();
            // 检查不允许推送的渠道（outChannelArray）
            List<String> outChannelList = JSON.parseArray(outChannelArray, String.class);
            if (CollUtil.isNotEmpty(outChannelList) && outChannelList.contains(channelCode)) {
                continue;
            }

            String inChannelArray = productOnlieInfo.getInChannelArray();
            // 检查允许推送的渠道（inChannelArray）
            List<String> inChannelList = JSON.parseArray(inChannelArray, String.class);
            if (CollUtil.isNotEmpty(inChannelList) && !inChannelList.contains(channelCode)) {
                continue;
            }

            String outCodeArray = productOnlieInfo.getOutCodeArray();
            List<String> outCodeList = JSON.parseArray(outCodeArray, String.class);
            if(CollUtil.isNotEmpty(outCodeList) && outCodeList.contains(channelBaseInfo.getAppCode())){
                continue;
            }

            //检查周几进行推送
            int dayOfWeek = LocalDate.now().getDayOfWeek().getValue();
            String today = String.valueOf(dayOfWeek);
            String notPushDayWeek = productOnlieInfo.getNotPushDayWeek();
            List<String> notPushDayWeeklist = JSON.parseArray(notPushDayWeek, String.class);
            if (CollUtil.isNotEmpty(notPushDayWeeklist) && notPushDayWeeklist.contains(today)) {
                continue;
            }
            //检查推送城市
//            String cityInfo = productOnlieInfo.getCityInfo();
//            List<String> cityInfoList = JSON.parseArray(cityInfo, String.class);
//            if(CollUtil.isNotEmpty(cityInfoList) && !cityInfoList.contains(cityInfo)){
//                continue;
//            }
            //检查不推送城市
//            String outCityArray = productOnlieInfo.getOutCityArray();
//            List<String> outCityList = JSON.parseArray(outCityArray, String.class);
//            if(CollUtil.isNotEmpty(outCityList) && outCityList.contains(outCityArray)){
//                continue;
//            }


            // 2023/9/2 uv 控量 ，查询是否展示
            String redisKey = StrUtil.format(RedisKeyConstant.PRODUCT_UV_REMAIN_COUNT_KEY, nowDate, productOnlieInfo.getProductId());
            String remainNumber = stringRedisTemplate.opsForValue().get(redisKey);
            if (ObjectUtil.isNotEmpty(remainNumber) && Integer.valueOf(remainNumber) <= 0) {
                continue;
            }

//            stringRedisTemplate.opsForSet().add(redisIdKey, productId);
            //封装
            ProductBaseInfo productInfo = productBaseInfoService.getProductInfoById(productOnlieInfo.getProductId());
            dataList .addAll(buildProductInfoVO(productInfo, productOnlieInfo, uid,channelBaseInfo));
            //dataList.add(productInfoVO);


            //return new ResponseVo(AppRspCodeConstant.SUCCESS, jsonObject);
        }
        //没有产品返回时返回空列表
        jsonObject.put("dataList", dataList);
        return new ResponseVo(AppRspCodeConstant.SUCCESS, jsonObject);
    }


    @Override
    public ResponseVo getLoanOverProduct(ChannelBaseInfo channelBaseInfo, String sceneId, Long uid) {

        // 渠道是否展示产品
        if (!ObjectUtil.equals(Integer.valueOf(1), channelBaseInfo.getShowProductFlag())) {
            // 不展示产品列表的时候，返回空几个
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("dataList", new ArrayList<>());
            return new ResponseVo(AppRspCodeConstant.SUCCESS, jsonObject);
        }
        String nowDate = LocalDate.now().toString();
        String nowTime = LocalDateUtil.getNowDateStr(LocalDateUtil.SIMPLE_TIME);
        String channelCode = channelBaseInfo.getChannelCode();
        JSONObject jsonObject = new JSONObject();

        // 查询已经上线的产品
        List<ProductOnlieInfo> onlieInfoList = this.baseMapper.getOnlineProductInfoList(sceneId, channelBaseInfo.getChannelType(), nowDate, nowTime);
        MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.getEntityByUidLock(uid);
        if(memberSourceInfo == null){
            jsonObject.put("dataList", new ArrayList<>());
            return new ResponseVo(AppRspCodeConstant.SUCCESS, jsonObject);
        }
        onlieInfoList.sort((p1, p2) -> p2.getPriceAmount().compareTo(p1.getPriceAmount()));
        onlieInfoList = filterProductInfoByZhimaFilter(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByYuQi(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByloanAmount(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByXueLi(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByJob(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByShouRu(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByHouse(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByCar(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByGjj(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByShebao(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByBaoxian(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByHubei(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByBaitiao(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByYongtu(onlieInfoList, uid);

        onlieInfoList = filterProductInfoByAge(onlieInfoList, memberSourceInfo);

        onlieInfoList = filterProductInfoByCtiy(onlieInfoList, uid);

        onlieInfoList = filterProductInfoByOutCtiy(onlieInfoList, uid);


        // 用于记录已经添加过的“仅展示一次”的产品ID
        //Set<String> shownOnceProducts = new HashSet<>();
        List<ProductInfoVO> dataList = new ArrayList<>();
        String redisIdKey = RedisKeyConstant.PRODUCT_OVER_ID + uid;
        Set<String> matchedProductIds = stringRedisTemplate.opsForSet().members(redisIdKey);
        for (ProductOnlieInfo productOnlieInfo : onlieInfoList) {
            String productId = String.valueOf(productOnlieInfo.getProductId());

            //跳过以匹配过的产品
            if (CollUtil.isNotEmpty(matchedProductIds) && matchedProductIds.contains(productId)) {
                continue;
            }

            String outChannelArray = productOnlieInfo.getOutChannelArray();
            // 检查不允许推送的渠道（outChannelArray）
            List<String> outChannelList = JSON.parseArray(outChannelArray, String.class);
            if (CollUtil.isNotEmpty(outChannelList) && outChannelList.contains(channelCode)) {
                continue;
            }

            String inChannelArray = productOnlieInfo.getInChannelArray();
            // 检查允许推送的渠道（inChannelArray）
            List<String> inChannelList = JSON.parseArray(inChannelArray, String.class);
            if (CollUtil.isNotEmpty(inChannelList) && !inChannelList.contains(channelCode)) {
                continue;
            }

            String outCodeArray = productOnlieInfo.getOutCodeArray();
            List<String> outCodeList = JSON.parseArray(outCodeArray, String.class);
            if(CollUtil.isNotEmpty(outCodeList) && outCodeList.contains(channelBaseInfo.getAppCode())){
                continue;
            }

            //检查周几进行推送
            int dayOfWeek = LocalDate.now().getDayOfWeek().getValue();
//            String today = String.valueOf(dayOfWeek == 7 ? dayOfWeek : dayOfWeek);
            String today = String.valueOf(dayOfWeek);
            String notPushDayWeek = productOnlieInfo.getNotPushDayWeek();
            List<String> notPushDayWeeklist = JSON.parseArray(notPushDayWeek, String.class);
            if (CollUtil.isNotEmpty(notPushDayWeeklist) && notPushDayWeeklist.contains(today)) {
                continue;
            }
            //String sceneIds = productOnlieInfo.getSceneId();

//            if (StrUtil.isNotEmpty(sceneIds) && sceneIds.contains("4")) {
//                if (shownOnceProducts.contains(productId)) {
//                    continue;
//                }
//                shownOnceProducts.add(productId);
//            }
            String redisKey = StrUtil.format(RedisKeyConstant.PRODUCT_UV_REMAIN_COUNT_KEY, nowDate, productOnlieInfo.getProductId());
            String remainNumber = stringRedisTemplate.opsForValue().get(redisKey);
            if (ObjectUtil.isNotEmpty(remainNumber) && Integer.valueOf(remainNumber) <= 0) {
                continue;
            }
            ProductBaseInfo productInfo = productBaseInfoService.getProductInfoById(productOnlieInfo.getProductId());
            dataList .addAll(buildProductInfoVO(productInfo, productOnlieInfo, uid,channelBaseInfo));
            //dataList.add(productInfoVO);

            //return new ResponseVo(AppRspCodeConstant.SUCCESS, jsonObject);

        }
        jsonObject.put("dataList", dataList);
        return new ResponseVo(AppRspCodeConstant.SUCCESS, jsonObject);
    }

    @Override
    public List<ProductOnlieInfo> getWeCom(Long uid,ChannelBaseInfo channelBaseInfo) {
        String channelCode = channelBaseInfo.getChannelCode();
        String nowDate = LocalDate.now().toString();
        String nowTime = LocalDateUtil.getNowDateStr(LocalDateUtil.SIMPLE_TIME);
        List<ProductOnlieInfo> onlieInfoList = this.baseMapper.getWeCom(nowDate,nowTime);
        MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        onlieInfoList = filterProductInfoByZhimaFilter(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByYuQi(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByloanAmount(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByXueLi(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByJob(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByShouRu(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByHouse(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByCar(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByGjj(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByShebao(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByBaoxian(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByHubei(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByBaitiao(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByYongtu(onlieInfoList, uid);
        onlieInfoList = filterProductInfoByAge(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByCtiy(onlieInfoList, uid);
        onlieInfoList = filterProductInfoByOutCtiy(onlieInfoList, uid);
        onlieInfoList.sort((p1, p2) -> p2.getPriceAmount().compareTo(p1.getPriceAmount()));
        for (ProductOnlieInfo productOnlieInfo : onlieInfoList) {

            ArrayList<ProductOnlieInfo> resultList = new ArrayList<>();
            String outChannelArray = productOnlieInfo.getOutChannelArray();
            // 检查不允许推送的渠道（outChannelArray）
            List<String> outChannelList = JSON.parseArray(outChannelArray, String.class);
            if (CollUtil.isNotEmpty(outChannelList) && outChannelList.contains(channelCode)) {
                return resultList;
            }

            String inChannelArray = productOnlieInfo.getInChannelArray();
            // 检查允许推送的渠道（inChannelArray）
            List<String> inChannelList = JSON.parseArray(inChannelArray, String.class);
            if (CollUtil.isNotEmpty(inChannelList) && !inChannelList.contains(channelCode)) {
                return resultList;
            }

            //检查周几进行推送
            int dayOfWeek = LocalDate.now().getDayOfWeek().getValue();
            String today = String.valueOf(dayOfWeek);
            String notPushDayWeek = productOnlieInfo.getNotPushDayWeek();
            List<String> notPushDayWeeklist = JSON.parseArray(notPushDayWeek, String.class);
            if (CollUtil.isNotEmpty(notPushDayWeeklist) && notPushDayWeeklist.contains(today)) {
                return resultList;
            }
            String outCodeArray = productOnlieInfo.getOutCodeArray();
            List<String> outCodeList = JSON.parseArray(outCodeArray, String.class);
            if(CollUtil.isNotEmpty(outCodeList) && outCodeList.contains(channelBaseInfo.getAppCode())){
                return resultList;
            }
        }

        return onlieInfoList;
    }

    @Override
    public List<ProductOnlieInfo> getWeCom1(MemberSourceInfo memberSourceInfo, ChannelBaseInfo channelBaseInfo) {
        String channelCode = channelBaseInfo.getChannelCode();
        String nowDate = LocalDate.now().toString();
        String nowTime = LocalDateUtil.getNowDateStr(LocalDateUtil.SIMPLE_TIME);
        List<ProductOnlieInfo> onlieInfoList = this.baseMapper.getWeCom(nowDate,nowTime);
        onlieInfoList = filterProductInfoByZhimaFilter(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByYuQi(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByAge(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByXueLi(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByloanAmount(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByJob(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByShouRu(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByHouse(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByCar(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByGjj(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByShebao(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByBaoxian(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByHubei(onlieInfoList, memberSourceInfo);
        onlieInfoList = filterProductInfoByBaitiao(onlieInfoList, memberSourceInfo);
        onlieInfoList.sort((p1, p2) -> p2.getPriceAmount().compareTo(p1.getPriceAmount()));
        return onlieInfoList;
    }


    private List<ProductOnlieInfo> filterProductInfoByOutCtiy(List<ProductOnlieInfo> productPushList, Long uid) {
        MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        // 如果用户信息为空，直接返回原列表
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String cityCode = memberSourceInfo.getCityCode();
        List<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String outCityArray = productPush.getOutCityArray();
                if (StrUtil.isEmpty(outCityArray)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> outCtiyList = JSON.parseArray(outCityArray, String.class);
                if (CollUtil.isEmpty(outCtiyList)) {
                    resultList.add(productPush);
                    continue;
                }
                //不推送城市里有用户信息值 则产品不添加
                if (StrUtil.isNotEmpty(cityCode) && !outCityArray.contains(cityCode)) {
                    resultList.add(productPush);
                }
            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }

    private List<ProductOnlieInfo> filterProductInfoByCtiy(List<ProductOnlieInfo> productPushList, Long uid) {
        MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        // 如果用户信息为空，直接返回原列表
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String cityCode = memberSourceInfo.getCityCode();
        List<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String cityInfo = productPush.getCityInfo();
                if (StrUtil.isEmpty(cityInfo)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> codeList = JSON.parseArray(cityInfo, String.class);
                if (CollUtil.isEmpty(codeList)) {
                    resultList.add(productPush);
                    continue;
                }
                if (StrUtil.isNotEmpty(cityCode) && !cityInfo.contains(cityCode)) {
                    resultList.add(productPush);
                }
            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }


    private List<ProductOnlieInfo> filterProductInfoByAge(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {
        //MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        // 如果用户信息为空，直接返回原列表
        if (memberSourceInfo == null) {
            return productPushList;
        }

        Integer age = memberSourceInfo.getAge();

        List<ProductOnlieInfo> resultList = new ArrayList<>();
        try {

            for (ProductOnlieInfo productPush : productPushList) {
                Integer maxAge = productPush.getMaxAge();
                Integer minAge = productPush.getMinAge();

                // 如果最大年龄或最小年龄为空，则跳过该产品的年龄筛选
//                if (maxAge == null && minAge == null) {
//                    resultList.add(productPush);
//                    continue;
//                }

                // 如果最大年龄不为空，且用户年龄大于最大年龄，则跳过该产品
                if (maxAge != null && age > maxAge) {
                    continue;
                }

                // 如果最小年龄不为空，且用户年龄小于最小年龄，则跳过该产品
                if (minAge != null && age < minAge) {
                    continue;
                }

                // 如果满足年龄范围，则加入到结果列表
                resultList.add(productPush);
            }

            return resultList;
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return productPushList;
    }


    private List<ProductOnlieInfo> filterProductInfoByYongtu(List<ProductOnlieInfo> productPushList, Long uid) {
        MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String yongtu = memberSourceInfo.getYongtu();
        ArrayList<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String yongtu1 = productPush.getYongtu();
                if (StrUtil.isEmpty(yongtu1)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> yongtuList = JSON.parseArray(yongtu1, String.class);
                if (CollUtil.isEmpty(yongtuList)) {
                    resultList.add(productPush);
                    continue;
                }
                if (StrUtil.isNotEmpty(yongtu) && yongtu1.contains(yongtu)) {
                    resultList.add(productPush);
                }
            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }

    private List<ProductOnlieInfo> filterProductInfoByBaitiao(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {
        //MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String baitiao = memberSourceInfo.getBaitiao();
        ArrayList<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String baitiao1 = productPush.getBaitiao();
                if (StrUtil.isEmpty(baitiao1)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> baitiaoList = JSON.parseArray(baitiao1, String.class);
                if (CollUtil.isEmpty(baitiaoList)) {
                    resultList.add(productPush);
                    continue;
                }
                if (StrUtil.isNotEmpty(baitiao) && baitiao1.contains(baitiao)) {
                    resultList.add(productPush);
                }
            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }

    private List<ProductOnlieInfo> filterProductInfoByHubei(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {
        //MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String huabei = memberSourceInfo.getHuabei();
        ArrayList<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String huabei1 = productPush.getHuabei();
                if (StrUtil.isEmpty(huabei1)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> huabeiList = JSON.parseArray(huabei1, String.class);
                if (CollUtil.isEmpty(huabeiList)) {
                    resultList.add(productPush);
                    continue;
                }
                if (StrUtil.isNotEmpty(huabei) && huabei1.contains(huabei)) {
                    resultList.add(productPush);
                }
            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }

    private List<ProductOnlieInfo> filterProductInfoByBaoxian(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {
        //MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String baoxian = memberSourceInfo.getBaoxian();
        ArrayList<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String baoxian1 = productPush.getBaoxian();
                if (StrUtil.isEmpty(baoxian1)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> baoxianList = JSON.parseArray(baoxian1, String.class);
                if (CollUtil.isEmpty(baoxianList)) {
                    resultList.add(productPush);
                    continue;
                }
                if (StrUtil.isNotEmpty(baoxian) && baoxian1.contains(baoxian)) {
                    resultList.add(productPush);
                }
            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }

    private List<ProductOnlieInfo> filterProductInfoByShebao(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {
        //MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String shebao = memberSourceInfo.getShebao();
        ArrayList<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String shebao1 = productPush.getShebao();
                if (StrUtil.isEmpty(shebao1)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> shebaoList = JSON.parseArray(shebao1, String.class);
                if (CollUtil.isEmpty(shebaoList)) {
                    resultList.add(productPush);
                    continue;
                }
                if (StrUtil.isNotEmpty(shebao) && shebao1.contains(shebao)) {
                    resultList.add(productPush);
                }
            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }

    private List<ProductOnlieInfo> filterProductInfoByGjj(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {
        //MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String gjj = memberSourceInfo.getGjj();
        ArrayList<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String gjj1 = productPush.getGjj();
                if (StrUtil.isEmpty(gjj1)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> gjjList = JSON.parseArray(gjj1, String.class);
                if (CollUtil.isEmpty(gjjList)) {
                    resultList.add(productPush);
                    continue;
                }
                if (StrUtil.isNotEmpty(gjj) && gjj1.contains(gjj)) {
                    resultList.add(productPush);

                }
            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }


    private List<ProductOnlieInfo> filterProductInfoByCar(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {
        //MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String car = memberSourceInfo.getCar();
        ArrayList<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String car1 = productPush.getCar();
                if (StrUtil.isEmpty(car1)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> carList = JSON.parseArray(car1, String.class);
                if (CollUtil.isEmpty(carList)) {
                    resultList.add(productPush);
                    continue;
                }
                if (StrUtil.isNotEmpty(car) && car1.contains(car)) {
                    resultList.add(productPush);
                }
            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }

    private List<ProductOnlieInfo> filterProductInfoByHouse(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {
        //MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String house = memberSourceInfo.getHouse();
        ArrayList<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String house1 = productPush.getHouse();
                if (StrUtil.isEmpty(house1)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> houseList = JSON.parseArray(house1, String.class);
                if (CollUtil.isEmpty(houseList)) {
                    resultList.add(productPush);
                    continue;
                }
                if (StrUtil.isNotEmpty(house) && house1.contains(house)) {
                    resultList.add(productPush);
                }
            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }

    private List<ProductOnlieInfo> filterProductInfoByShouRu(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {
        //MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String shouru = memberSourceInfo.getShouru();
        ArrayList<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String shouru1 = productPush.getShouru();
                if (StrUtil.isEmpty(shouru1)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> shouruList = JSON.parseArray(shouru1, String.class);
                if (CollUtil.isEmpty(shouruList)) {
                    resultList.add(productPush);
                    continue;
                }
                if (StrUtil.isNotEmpty(shouru) && shouru1.contains(shouru)) {
                    resultList.add(productPush);
                }
            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }

    private List<ProductOnlieInfo> filterProductInfoByJob(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {
        //MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String gongzuo = memberSourceInfo.getGongzuo();
        ArrayList<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String gongzuo1 = productPush.getGongzuo();
                if (StrUtil.isEmpty(gongzuo1)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> gongzuoList = JSON.parseArray(gongzuo1, String.class);
                if (CollUtil.isEmpty(gongzuoList)) {
                    resultList.add(productPush);
                    continue;
                }
                if (StrUtil.isNotEmpty(gongzuo) && gongzuo1.contains(gongzuo)) {
                    resultList.add(productPush);
                }
            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }

    private List<ProductOnlieInfo> filterProductInfoByXueLi(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {
        //MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String xueli = memberSourceInfo.getXueli();
        ArrayList<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String xueli1 = productPush.getXueli();
                if (StrUtil.isEmpty(xueli1)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> xueLiList = JSON.parseArray(xueli1, String.class);
                if (CollUtil.isEmpty(xueLiList)) {
                    resultList.add(productPush);
                    continue;
                }
                if (StrUtil.isNotEmpty(xueli) && xueli1.contains(xueli)) {
                    resultList.add(productPush);
                }
            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }

    private List<ProductOnlieInfo> filterProductInfoByloanAmount(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {
        //MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if (memberSourceInfo == null) {
            return productPushList;
        }
        String loanAmount = memberSourceInfo.getLoanAmount();
        ArrayList<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {

                String loanAmount1 = productPush.getLoanAmount();

                if (StrUtil.isEmpty(loanAmount1)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> loanAmountList = JSON.parseArray(loanAmount1, String.class);
                if (CollUtil.isEmpty(loanAmountList)) {
                    resultList.add(productPush);
                    continue;
                }
                if (StrUtil.isNotEmpty(loanAmount) && loanAmount1.contains(loanAmount)) {
                    resultList.add(productPush);
                }

            }
            return resultList;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return productPushList;
    }

    private List<ProductOnlieInfo> filterProductInfoByYuQi(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {
        // 获取用户信息
        //MemberSourceInfo memberSourceInfo = memberSourceInfoMapper.selectById(uid);
        if (memberSourceInfo == null) {
            return productPushList; // 用户信息不存在，直接返回原产品列表
        }

        String userYuQi = memberSourceInfo.getYuqi();

        List<ProductOnlieInfo> resultList = new ArrayList<>();
        try {
            for (ProductOnlieInfo productPush : productPushList) {
                String productYuQi = productPush.getYuqi();

                if (StrUtil.isEmpty(productYuQi)) {
                    resultList.add(productPush);
                    continue;
                }
                List<String> yuqiList = JSON.parseArray(productYuQi, String.class);
                if(CollUtil.isEmpty(yuqiList)){
                    resultList.add(productPush);
                    continue;
                }

                // 如果产品需要筛选逾期，只有 "无逾期" (yq001) 的用户才添加
                if (StrUtil.isNotEmpty(userYuQi) &&  productYuQi.contains(userYuQi)) {
                    resultList.add(productPush);
                }
            }
        } catch (Exception exception) {
            exception.printStackTrace();
        }

        return resultList;
    }

    public  List<ProductInfoVO> buildProductInfoVO(ProductBaseInfo productInfo, ProductOnlieInfo productOnlieInfo, Long uid,ChannelBaseInfo channelBaseInfo) {
        ProductInfoVO productInfoVO = new ProductInfoVO();
        productInfoVO.setProductId(String.valueOf(productInfo.getId()));
        productInfoVO.setProductName(productInfo.getProductName());
        productInfoVO.setProductLogo(productInfo.getLogoUrl());
        productInfoVO.setProductTitle(productInfo.getTitleInfo());
        productInfoVO.setProductLabel(productInfo.getLabelInfo());
        productInfoVO.setShowFlag(productInfo.getShowFlag());
        productInfoVO.setDownloadFlag(productInfo.getDownloadFlag());
        productInfoVO.setMaxAmount(productInfo.getMaxAmount());
        productInfoVO.setJumpStatus(productOnlieInfo.getJumpStatus());
        productInfoVO.setSpeed(productInfo.getSpeed());
        productInfoVO.setLoanTime(productInfo.getLoanTime());
        productInfoVO.setSublabelInfo(productInfo.getSublabelInfo());
        productInfoVO.setRateAmountInfo(productInfo.getMinRate()+"%");

        List<Map<String, String>> protocolList = new ArrayList<>();


        if ("101".equals(String.valueOf(productInfo.getId()))) {
            HashMap<String, String> map = new HashMap<>();
            map.put("name","用户协议");
            map.put("url",StrUtil.format("https://api.hlai.hengtdb.com/page/jinYaoHua1/{}.html", uid));
            map.put("key","privacy");
            protocolList.add(map);
            HashMap<String, String> map1 = new HashMap<>();
            map1.put("name","隐私政策");
            map1.put("url",StrUtil.format("https://api.hlai.hengtdb.com/page/jinYaoHua/{}.html", uid));
            map1.put("key","privacyLevel");
            protocolList.add(map1);
        }

        if ("111".equals(String.valueOf(productInfo.getId()))) {
            HashMap<String, String> map = new HashMap<>();
            map.put("name","用户服务协议");
            map.put("url",StrUtil.format("https://api.hlai.hengtdb.com/page/RongYouKe/{}.html", uid));
            map.put("key","privacy");
            protocolList.add(map);
            HashMap<String, String> map1 = new HashMap<>();
            map1.put("name","隐私政策");
            map1.put("url",StrUtil.format("https://api.hlai.hengtdb.com/page/RongYouKe1/{}.html", uid));
            map1.put("key","privacyLevel");
            protocolList.add(map1);
        }
        if ("115".equals(String.valueOf(productInfo.getId())) || "116".equals(String.valueOf(productInfo.getId()))) {
            HashMap<String, String> map = new HashMap<>();
            map.put("name","用户服务协议");
            map.put("url","https://wap.kedqb.cn/xy/yhzcfwxy.html?urlParam=%7B%22myCompanyAddress%22:%22%E4%B8%AD%E5%9B%BD%EF%BC%88%E5%9B%9B%E5%B7%9D%EF%BC%89%E8%87%AA%E7%94%B1%E8%B4%B8%E6%98%93%E8%AF%95%E9%AA%8C%E5%8C%BA%E6%88%90%E9%83%BD%E9%AB%98%E6%96%B0%E5%8C%BA%E9%94%A6%E5%9F%8E%E5%A4%A7%E9%81%93666%E5%8F%B7%E9%99%8451%E5%8F%B71%E6%A5%BC2311%E5%8F%B7%EF%BC%88%E8%87%AA%E7%BC%96%E5%8F%B7%EF%BC%89%22,%22myCompanyName%22:%22%E6%88%90%E9%83%BD%E5%B7%A8%E8%8A%92%E4%BF%A1%E6%81%AF%E7%A7%91%E6%8A%80%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8%22,%22appName%22:%22%E5%8F%AF%E8%B4%B7%E9%92%B1%E5%8C%85%22,%22bodyCode%22:%22kdqb%22%7D");
            map.put("key","privacy");
            protocolList.add(map);
            HashMap<String, String> map1 = new HashMap<>();
            map1.put("name","隐私政策");
            map1.put("url","https://wap.kedqb.cn/xy/yszc.html?urlParam=%7B%22myCompanyAddress%22:%22%E4%B8%AD%E5%9B%BD%EF%BC%88%E5%9B%9B%E5%B7%9D%EF%BC%89%E8%87%AA%E7%94%B1%E8%B4%B8%E6%98%93%E8%AF%95%E9%AA%8C%E5%8C%BA%E6%88%90%E9%83%BD%E9%AB%98%E6%96%B0%E5%8C%BA%E9%94%A6%E5%9F%8E%E5%A4%A7%E9%81%93666%E5%8F%B7%E9%99%8451%E5%8F%B71%E6%A5%BC2311%E5%8F%B7%EF%BC%88%E8%87%AA%E7%BC%96%E5%8F%B7%EF%BC%89%22,%22myCompanyName%22:%22%E6%88%90%E9%83%BD%E5%B7%A8%E8%8A%92%E4%BF%A1%E6%81%AF%E7%A7%91%E6%8A%80%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8%22,%22appName%22:%22%E5%8F%AF%E8%B4%B7%E9%92%B1%E5%8C%85%22,%22bodyCode%22:%22kdqb%22%7D");
            map1.put("key","privacyLevel");
            protocolList.add(map1);
        }
        if ("126".equals(String.valueOf(productInfo.getId())) || "116".equals(String.valueOf(productInfo.getId()))) {
            HashMap<String, String> map = new HashMap<>();
            map.put("name","用户服务协议");
            map.put("url","https://pro.nahezihz.com/agreement/xyu9rxWkqQL");
            map.put("key","privacy");
            protocolList.add(map);
            HashMap<String, String> map1 = new HashMap<>();
            map1.put("name","隐私政策");
            map1.put("url","https://pro.nahezihz.com/agreement/xynT7TnsSFV");
            map1.put("key","privacyLevel");
            protocolList.add(map1);
        }
        productInfoVO.setPrivacy(protocolList);
        List<ProductInfoVO> dataList = new ArrayList<>();
        boolean unionFlag = ObjectUtil.equals(productInfo.getChargeType(), ChargeTypeEnum.UNION.getValue());
        productInfoVO.setUnionFlag(unionFlag);
        if (unionFlag) {
            UnionLoginResult loginResult = productUnionLoginService.getUnionProductShowInfo(productInfo, uid,channelBaseInfo);
            log.info("【产品列表】产品联登【productId】{}【uid】{}【result】{}", productInfo.getId(), uid, JSON.toJSONString(loginResult));
            if (loginResult.isSuccess()) {
                String loginUrl = loginResult.getLoginUrl();
                if (StrUtil.isNotEmpty(loginUrl)) {
                    productInfoVO.setDetailUrl(loginResult.getLoginUrl());
                } else {
                    productInfoVO.setDetailUrl("");
                }
                dataList.add(productInfoVO);
            }
        } else {
            productInfoVO.setDetailUrl(productInfo.getDetailUrl());
            dataList.add(productInfoVO);
        }
        return  dataList;
    }

    private List<ProductOnlieInfo> filterProductInfoByZhimaFilter(List<ProductOnlieInfo> productPushList, MemberSourceInfo memberSourceInfo) {


        // 如果用户信息为空或者芝麻分为空，直接返回原列表
        if (memberSourceInfo == null || StrUtil.isEmpty(memberSourceInfo.getZhima())) {
            return productPushList;
        }
        String zhima = memberSourceInfo.getZhima();

        List<ProductOnlieInfo> resultList = new ArrayList<>();
        try {

            for (ProductOnlieInfo productPush : productPushList) {

                String zhimaFilter = productPush.getZhima();
                // 芝麻过滤为空，产品显示
                if (StrUtil.isEmpty(zhimaFilter)) {
                    resultList.add(productPush);
                    continue;
                }

                List<String> zhimaFilterList = JSON.parseArray(zhimaFilter, String.class);
                // 芝麻过滤为空，产品显示
                if (CollUtil.isEmpty(zhimaFilterList)) {
                    resultList.add(productPush);
                    continue;
                }

                if (StrUtil.isNotEmpty(zhima) && zhimaFilter.contains(zhima)) {
                    // 芝麻过滤不为空，且用户芝麻在过滤范围内
                    resultList.add(productPush);
                }
            }
            return resultList;
        } catch (Exception exception) {
            exception.printStackTrace();
        }
        return productPushList;
    }

}
